import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../../base/imageres.dart';
import '../../base/constant.dart';
import '../../base/eventbus.dart';
import '../../base/stringres.dart';
import '../../base/theme.dart';
import '../../native/nativechannel.dart';
import '../../views/jsw_base_view.dart';

///女性健康下面的目标设置
class TargetSettingPage extends StatefulWidget {
  final int tracking;

  const TargetSettingPage({super.key, required this.tracking});

  @override
  State<StatefulWidget> createState() {
    return _TargetSettingPageState();
  }
}

class _TargetSettingPageState extends State<TargetSettingPage> {
  static const _tag = '[page_target_setting.dart][_TargetSettingPageState]';

  ///女性健康目标值(0：受孕 1：周期跟踪 )
  var _tracking = 1;

  @override
  void initState() {
    super.initState();
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
        overlays: SystemUiOverlay.values);
    _tracking = widget.tracking;
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Container(
          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage(ImageRes.bg_health_set),
              fit: BoxFit.cover, // 图片填充方式
            ),
          ),
        ),
        JSWBaseView(
          bodyColor: Colors.transparent,
          head: AppBar(
            elevation: 0.0,
            backgroundColor: Colors.transparent,
            title: EasyTouch(
              width: double.infinity,
              padding: const EdgeInsets.only(right: 55),
              child: Text(
                StringRes.target,
                textAlign: TextAlign.center,
                style: ThemeUtil.toolbar,
              ),
            ),
            leading: IconButton(
              splashColor: Colors.transparent,
              highlightColor: Colors.transparent,
              hoverColor: Colors.transparent,
              icon: const Icon(
                Icons.arrow_back,
                color: Colors.white,
              ),
              onPressed: () {
                Get.back();
              },
            ),
          ),
          body: Column(
            children: [
              //内容
              Container(
                  margin: const EdgeInsets.only(top: 30, left: 20, right: 20),
                  child: Text(
                    textAlign: TextAlign.center,
                    StringRes.women_target_content,
                    style: ThemeUtil.h1.copyWith(fontSize: 20)
                  )),

              //提示
              Container(
                  margin: const EdgeInsets.only(top: 10, left: 30, right: 30),
                  child: Text(
                    StringRes.women_target_tips,
                    textAlign: TextAlign.center,
                    style: ThemeUtil.p2.copyWith(
                        color: const Color(ThemeUtil.primaryWhiteValue50)),
                  )),
              //周期跟踪
              JSWLine(
                clickable: true,
                margin: const EdgeInsets.only(top: 30, left: 15, right: 15),
                padding: const EdgeInsets.only(
                    top: 10, bottom: 10, left: 20, right: 12),
                decoration: BoxDecoration(
                  color: Colors.white12,
                  borderRadius: BorderRadius.circular(20.0), // 设置圆角半径
                  border: Border.all(
                      width: 1,
                      color:
                          _tracking == 1 ? Colors.white70 : Colors.transparent),
                ),
                onPressed: () {
                  setState(() {
                    _tracking = 1;
                  });
                },
                children: [
                  BaseViewItem(
                      weight: 5,
                      child: const Image(
                        image: AssetImage(ImageRes.ic_cycle_tracking),
                      )),
                  BaseViewItem(weight: 1, child: Container()),
                  BaseViewItem(
                    weight: 25,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          textAlign: TextAlign.left,
                          StringRes.cycle_tracking_content,
                          style: ThemeUtil.p2.copyWith(fontFamily: 'Medium'),
                        ),
                        Container(
                            margin: const EdgeInsets.only(top: 2),
                            child: Text(
                              StringRes.cycle_tracking_tips,
                              style: ThemeUtil.p2.copyWith(
                                  fontSize: 13,
                                  color: const Color(
                                      ThemeUtil.primaryWhiteValue50)),
                            )),
                      ],
                    ),
                  )
                ],
              ),

              //受孕
              JSWLine(
                clickable: true,
                margin: const EdgeInsets.only(top: 15, left: 15, right: 15),
                padding: const EdgeInsets.only(
                    top: 10, bottom: 10, left: 20, right: 12),
                decoration: BoxDecoration(
                  color: Colors.white12,
                  borderRadius: BorderRadius.circular(20.0), // 设置圆角半径
                  border: Border.all(
                      width: 1,
                      color:
                          _tracking == 0 ? Colors.white70 : Colors.transparent),
                ),
                onPressed: () {
                  setState(() {
                    _tracking = 0;
                  });
                },
                children: [
                  BaseViewItem(
                      weight: 5,
                      child: const Image(
                        image: AssetImage(ImageRes.ic_women_conception),
                      )),
                  BaseViewItem(weight: 1, child: Container()),
                  BaseViewItem(
                    weight: 25,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          textAlign: TextAlign.left,
                          StringRes.conception_content,
                          style: ThemeUtil.p2.copyWith(fontFamily: 'Medium'),
                        ),
                        Container(
                            margin: const EdgeInsets.only(top: 2),
                            child: Text(
                              StringRes.conception_tips,
                              style: ThemeUtil.p2.copyWith(
                                  fontSize: 13,
                                  color: const Color(
                                      ThemeUtil.primaryWhiteValue50)),
                            )),
                      ],
                    ),
                  )
                ],
              ),
            ],
          ),
          bottom: Container(
            margin: EdgeInsets.only(bottom: 30 + MediaQuery.of(context).viewPadding.bottom, left: 30, right: 30),
            child: //下一步按钮
                Container(
              height: 50,
              alignment: Alignment.center,
              decoration: ThemeUtil.themeConStyle,
              child: TextButton(
                style: ThemeUtil.themebtnStyle,
                onPressed: () async {
                  EventBusUtil.getInstance().fire(DataEvent(HealthDataType.REFRESH_SETTING_TARGETVALUE, _tracking));
                  Get.back();
                  if(_tracking == 0){
                    Native.setWomenConceptionData();
                  }
                },
                child: Text(StringRes.confirm,
                    textAlign: TextAlign.center, style: ThemeUtil.p2),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
